package com.heeexy.example.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.service.LogService;
import com.heeexy.example.util.CommonUtil;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/log")
public class LogController {

    @Autowired
    private LogService logService;

    @RequiresPermissions("user:list")
    @GetMapping("/getLog")
    public JSONObject getLog(HttpServletRequest request){

        return logService.getLog(CommonUtil.request2Json(request));
    }

    @RequiresPermissions(value = {"user:add", "user:update"}, logical = Logical.OR)
    @PostMapping("/updateLog")
    public JSONObject updateLog(@RequestBody JSONObject requestJson){
        CommonUtil.hasAllRequired(requestJson,"deleteStatus,logId");
        return logService.updateLog(requestJson);
    }
}
